import PubSub from "pubsub-js";
import { useState } from "react";

export default function Search() {
  const [keyword, setKeyword] = useState("");
  const handleChange = (e) => setKeyword(e.target.value);

  const handleClick = () => {
    if (!keyword) return;
    // 发布消息
    PubSub.publish("searchUserList", keyword);
  };

  return (
    <section className="jumbotron">
      <h3 className="jumbotron-heading">Search Github Users</h3>
      <div>
        <input
          type="text"
          placeholder="enter the name you search"
          onChange={handleChange}
        />
        <button onClick={handleClick}>Search</button>
      </div>
    </section>
  );
}
